# -*- coding:utf-8 -*-
"""
linux 部署
pip3 install django-cors-headers
            django
            uwsgi
            或者 gunicorn  # gunicorn -w 4 MVonline1.wsgi -b 0.0.0.0:9002 
            supervisor
            mysqlclient


1.yum install gcc mariadb-devel 



创建数据库 mysql
> create database `mvonline` character set utf8 collate utf8_general_ci;
python3 manage.py makemigrations
python3 manage.py migrate
> insert into app1_vip(grade, size) values(1,1);

python3 manage.py runserver 127.0.0.1:9002  # 本地端口

lsof -i:8000  # 查看端口被占用
killall -9 gunicorn

配置 supervisor
https://blog.csdn.net/guolindonggld/article/details/83386920

"""
# 部署的时候需要改变
HOST = 'http://localhost:8000'
# HOST = 'https://hhq-yyq.xyz:9001'   # 外网端口

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'mvonline',
        'USER': 'root',
        'PASSWORD': 'hhq',  # 需要修改
        'HOST': 'localhost',
        'PORT': '3306'
    }
}

import os
import pymysql  #引用mysql驱动
pymysql.install_as_MySQLdb()


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '5kpl3e0)tn2!fp+q$w(d_l8p$8t-%ig*@&n*lk4$%5xwj3#93p'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True    # 需要修改
ALLOWED_HOSTS = ['*']

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    # 'django.contrib.staticfiles',  # 取消自带的static
    #  my apps  below
    'app1',
    
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    # 'django.middleware.csrf.CsrfViewMiddleware',  # 取消csrf
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',

    'app1.my_middleware.LoginToken',

]

ROOT_URLCONF = 'MVonline1.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'MVonline1.wsgi.application'

# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases


# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/

LANGUAGE_CODE = 'zh-hans'

TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

USE_L10N = True

USE_TZ = True


FILE_PATH =  os.path.join(BASE_DIR,'files')
